package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.repository.FuncRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by ryan on 2018/1/30.
 */
@RestController
@RequestMapping("/func")
public class FunctionController {
    @Autowired
    private FuncRepository funcRepository;

    @GetMapping(value = {"/listFuncs","/listFuncs/{searchKey}"})
    public RespMsg listFuncs(@PathVariable(required = false) String searchKey){
        if (searchKey==null)
            return RespMsg.build(funcRepository.findAll());
        return RespMsg.build(funcRepository.findByFNameRegex(searchKey));
    }


}
